package com.handydata.antifraud.service.impl;

import com.handydata.antifraud.bo.orderbaseinfo.OrderBaseInfoReqBO;
import com.handydata.antifraud.bo.orderreturninfo.OrderReturnInfoReqBO;
import com.handydata.antifraud.enums.OperateStatusEnum;
import com.handydata.antifraud.enums.OperateTypeEnum;
import com.handydata.antifraud.enums.ProcessStatusEnum;
import com.handydata.antifraud.service.OrderBaseInfoService;
import com.handydata.antifraud.service.OrderReturnInfoService;
import com.handydata.antifraud.service.RiskResultProcessService;
import com.handydata.antifraud.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Component("riskResultProcessService")
public class RiskResultProcessServiceImpl implements RiskResultProcessService {

    @Autowired
    private OrderReturnInfoService orderReturnInfoService;

    @Autowired
    private OrderBaseInfoService orderBaseInfoService;

    @Transactional
    @Override
    public void process(OrderBaseInfoReqBO orderBaseInfoReqBO, OperateTypeEnum operateTypeEnum) {

        OrderReturnInfoReqBO orderReturnInfoReqBO = new OrderReturnInfoReqBO();
        orderReturnInfoReqBO.setOrderId(orderBaseInfoReqBO.getOrderId());
        orderReturnInfoReqBO.setOperateType(operateTypeEnum.getCode());
        orderReturnInfoReqBO.setOperateTime(DateUtil.localDateTimeToUdate());

        if(ProcessStatusEnum.RETURN_OK.getCode().equals(orderBaseInfoReqBO.getProcessState())) {
            //orderBaseInfoReqBO.setEndTime(DateUtil.localDateTimeToUdate());
            orderReturnInfoReqBO.setOperateStatus(OperateStatusEnum.OK.getCode());
        }else{
            orderReturnInfoReqBO.setOperateStatus(OperateStatusEnum.FAIL.getCode());
        }
        orderBaseInfoReqBO.setUpdateTime(DateUtil.localDateTimeToUdate());
        orderBaseInfoService.modifyOrderBaseInfoBy(orderBaseInfoReqBO);
        orderReturnInfoService.createOrderReturnInfo(orderReturnInfoReqBO);
    }
}
